package com.sale.plugins;

import com.apache.api.vo.ParamsVo;
import com.apache.database.constant.SpringContextLoader;
import com.apache.exception.BusinessException;
import com.apache.ius.plugin.CustomMethodPlugin;
import com.apache.match.manager.DealMatchingManager;

import java.util.HashMap;
import java.util.Map;

/**
 * 撤单操作
 */
public class SaleResultOrderPluginImpl implements CustomMethodPlugin {

    private DealMatchingManager dealMatchingManager;

    public Object beforeInvoke(Map<String, Object> param) {
        return resultOrder(param);
    }

    public Object doInvoke(Map<String, Object> param) {
        // TODO Auto-generated method stub
        return null;
    }

    public Object afterInvoke(Map<String, Object> param) {
        //		GoEasy goEasy = new GoEasy("fcdd060e-c3ee-4003-bdd7-d68785a77d19");
        //		goEasy.publish("my_channel", "InitDealMatchingPluginImpl发送的消息!");

        return resultOrder(param);
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    private Map<String, Object> resultOrder(Map<String, Object> param) {
        ParamsVo vo = new ParamsVo();
        vo.setParams(param);
        if (null == dealMatchingManager) {
            dealMatchingManager = ((DealMatchingManager) SpringContextLoader.getBean("dealMatchingManager"));
        }
        boolean mark = dealMatchingManager.resultOrder(vo);
        Map<String, Object> rmap = new HashMap<String, Object>();
        if (mark) {
            rmap.put("sqlKeyId", "S202");
            rmap.put("afterMethodKey", "S202");
            rmap.put("trsOrder.proNo", vo.getParams("trsOrder.proNo"));
            vo.setParams("businessSuccese", "撤销成功");
            //vo.setParams("afterMethodKey", "saleQuotationUpdate");
            //throw new BusinessException("撤销成功");

            rmap.put(CustomMethodPlugin.resultMark, "撤销成功");
            rmap.put(CustomMethodPlugin.pluginInnerReturn, "撤销成功");//3、准备返回值到Map中

        } else {
            throw new BusinessException(String.valueOf(vo.getParams("result-mssage")));
        }
        return rmap;
    }
}
